<!-- 求职意向 -->
<template>
	<view class="educationExperience card">	
		<view class='itemInfo'>
			<text>学校名称</text>
			<u-input placeholder="请填写" class="inputBox" border="none" disabledColor="#ffffff" v-model="personInfoData.itemWork.name"></u-input>
		</view>
		<view class='itemInfo'>
			<text>专业名称</text>
			<u-input placeholder="请填写" class="inputBox" border="none"  disabledColor="#ffffff" v-model="personInfoData.itemWork.position"></u-input>
		</view>
		<view class='itemInfo' @click="showsSelect('startTime')">
			<text>入学时间</text>
			
			<u-input placeholder="请选择" class="inputBox" border="none" disabled disabledColor="#ffffff" v-model="personInfoData.itemWork.startTime"></u-input>
		</view>
		<view class='itemInfo' @click="showsSelect('endTime')">
			<text>毕业时间</text>
			
			<u-input placeholder="请选择" class="inputBox" border="none" disabled disabledColor="#ffffff" v-model="personInfoData.itemWork.endTime"></u-input>
		</view>

		
		<view class="btnbox" v-if="selectFlag.pageType=='add'">
			<u-button class="custom-style" :plain="true" @click="editFun">保存</u-button>
		</view>
		<view class="btnbox" v-else>
			<u-button class="custom-style1" :plain="true" @click="deleteFun">删除</u-button>
			<u-button class="custom-style1" :plain="true" @click="editFun">保存</u-button>
		</view>
		
		
		<u-datetime-picker
			:minDate="14539098"
			:show="selectFlag.showSelect"
			v-model="personInfoData.time"
			mode="date"
			@confirm="confirmDate"
			@cancel="cancel"
		></u-datetime-picker>
		
	</view>
</template>

<script setup lang="ts">
	import { ref,reactive,getCurrentInstance } from 'vue'
	import {useRouter} from 'uni-mini-router'
	import {
		onLoad 
	} from '@dcloudio/uni-app'
	const {proxy} = getCurrentInstance()
	const router = useRouter()
	
	let personInfoData = reactive({
		info:{},
		minDate: new Date('1950-01-01').getTime(), // 确保传递一个数字类型的 Unix 时间戳
		time:'',
		itemWork:{},
		showTime:false,
	})
	
	let selectFlag = reactive({
		showSelect:false,
		pageType:'',
		type:'',
		idx:'',
		actions:[
			{name: '男'},
			{name: '女'},
		],
		positionAction:[
			{name: '2000'},
			{name: '2001'},
			{name: '2002'},
			{name: '2003'},
		],
		payAction:[
			{name: '2000-3000'},
			{name: '5000-7000'},
			{name: '8000-9000'},
			{name: '9000-13000'},
		],
		areaAction:[
			{name: '北京'},
			{name: '上海'},
		]
	})
	let SelectFun = (e)=>{
		personInfoData.sex = e.name
	}
	
	let showsSelect = (type)=>{
		selectFlag.type = type
		selectFlag.showSelect = true	
	}
	let confirmDate = (val)=>{
		console.log(val)
		const timeFormat = uni.$u.timeFormat
		if(selectFlag.type == 'startTime'){
			personInfoData.itemWork.startTime = timeFormat(val.value,'yyyy-mm-dd')
		}else if(selectFlag.type == 'endTime'){
			personInfoData.itemWork.endTime = timeFormat(val.value,'yyyy-mm-dd')
		}
		selectFlag.showSelect = false
	}
	let cancel = ()=>{
		selectFlag.showSelect = false
	}
	// 获取个人简历详情
	const meiyeRecruitHunterInfo2DetailsFun = ()=>{
		//获取详情
		proxy.$req('GET', proxy.$api.meiyeRecruitHunterInfo2Details).then((res) => {
			if(res.code === 200){
				personInfoData.info = res.result
				if(selectFlag.pageType == 'edit'){
					uni.setNavigationBarTitle({
						title:'修改教育经历'
					})
					personInfoData.itemWork = selectFlag.idx?personInfoData.info.schoolList[selectFlag.idx]:{}
				}
			}
		})
	}
	
	
	const editAjax = ()=>{
		
		proxy.$req('POST', proxy.$api.meiyeRecruitHunterInfo2edit,personInfoData.info).then((res) => {
			if(res.code === 200){
				router.back()
			}
		})
	}
	
	
	
	// 修改数据
	const editFun = ()=>{
		
		if(selectFlag.pageType == 'add'){
			personInfoData.itemWork.type = 1
			console.log(personInfoData.itemWork,'personInfoData.itemWork',personInfoData.info.schoolList)
			personInfoData.info.schoolList.splice(personInfoData.info.schoolList.length,0,personInfoData.itemWork)
		}else if(selectFlag.pageType == 'edit'){
			personInfoData.info.schoolList.splice(selectFlag.idx,1,personInfoData.itemWork)
		}
		console.log(personInfoData.info.schoolList,personInfoData.itemWork,'12121212')
		editAjax()
	}
	
	// 删除数据
	// const deleteFun = ()=>{
	// 	personInfoData.info.schoolList.splice(selectFlag.idx,1)
	// 	editAjax()
	// }
	
	// 删除数据
	const deleteFun = ()=>{
		let id = personInfoData.info.schoolList[selectFlag.idx].id
		proxy.$req('DELETE', proxy.$api.meiyeRecruitHuntMemberExperience3Delete,{id}).then((res) => {
			if(res.code === 200){
				router.back()
			}
		})
	}
	
	onLoad((option)=>{
		selectFlag.pageType = option.type
		selectFlag.idx = option.index
		meiyeRecruitHunterInfo2DetailsFun()
	})
</script>
<style lang="scss" scoped>
	page{
		background:#f6f6f6;
		padding:30rpx;
	}
	.card{
		background:#fff;
		box-sizing: border-box;
		border: 2rpx solid #fff;
		margin: 30rpx auto;
		padding: 24rpx;
		background:#fff;
		border-radius: 24rpx;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0, 0, 0, 0.04);
	}
	.educationExperience{
		.itemInfo{
			display:flex;
			// flex-direction: column;
			// align-items: center;
			padding:30rpx 0;
			border-bottom: 1rpx solid #eee;
			text{
				color:#000;
				font-size:32rpx;
				padding-bottom:20rpx;
				
			}
			:deep(.inputBox){
				background-color:#fff;
				.uni-input-input,.uni-input-placeholder{
					text-align: right !important;
					color:#8E8E93;
					font-size:30rpx;
				}
			} 
		}
		
		.btnbox{
			padding:100rpx 0rpx;
			display:flex;
			
			.custom-style {
				color: #fff;
				background-color: rgba(203, 100, 94, 1);
				width: 80%;
				border-radius: 14rpx;
			}
			
			.custom-style1{
				color: #fff;
				background-color: rgba(203, 100, 94, 1);
				width: 40%;
				border-radius: 14rpx;
			}
		}
	}
</style>